/**
 * 
 */
package com.shequan.silayer.internal.service.impl;

import org.apache.log4j.Logger;

import com.ailk.dazzle.util.SecurityUtils;
import com.shequan.common.bean.ResultDataStruct;
import com.shequan.common.bean.ViewTextConstans;
import com.shequan.common.bean.WebConstants;
import com.shequan.silayer.internal.bean.pojo.ItfEmailSend;
import com.shequan.silayer.internal.dao.ItfEmailSendDAO;
import com.shequan.silayer.internal.service.ItfEmailSendService;

/**
 * <P>
 * Copyright 2012.
 * </p>
 * <P>
 * All Rights Reserved.
 * </p>
 * @author YuJF
 * @version 1.0, 2012-3-1
 * @see com.shequan.silayer.internal.service.impl.ItfEmailSendServiceImpl 
 * @since 1.0
 */
public class ItfEmailSendServiceImpl implements ItfEmailSendService {
	private final static Logger log=Logger.getLogger(ItfEmailSendServiceImpl.class);
	private ItfEmailSendDAO itfEmailSendDAO;

	public void setItfEmailSendDAO(ItfEmailSendDAO itfEmailSendDAO) {
		this.itfEmailSendDAO = itfEmailSendDAO;
	}

	/* 
	 * @see com.shequan.silayer.internal.service.ItfEmailSendService#addEmailSend(java.lang.String, java.lang.String)
	 */
	public ResultDataStruct<String> addEmailSend(String userName, String userPwd) {
		log.debug("in addEmailSend");
		ResultDataStruct<String> rds=new ResultDataStruct<String>();
		ItfEmailSend record=new ItfEmailSend();
		String encryptValue;
		try {
			encryptValue=SecurityUtils.encryptByDES(userName+WebConstants.ENCRYPT_SEPARATIVE+userPwd, WebConstants.ENCRYPT_KEY);
			record.setReceiveUserEmail(userName);
			record.setSendStatus(WebConstants.EMAIL_SEND_STATUS_UNSEND);
			record.setSendContent(ViewTextConstans.EMAIL_SEND_ACTIVITY_CONTENT+"userName="+userName+"&"+WebConstants.ENCRYPT_VALUE+"="+encryptValue);
			itfEmailSendDAO.insertSelective(record);
			rds.setMessage(ViewTextConstans.EMAIL_SEND_SUCCESS);
			rds.setBusiSuccess(true);
		} catch (Exception e) {
			rds.setSuccess(false);
			rds.setMessage(ViewTextConstans.EMAIL_SEND_FAILS);
			log.error("",e);
		}
		return rds;
	}
	
}
